package com.jeejio.img.picker;

import android.net.Uri
import android.provider.MediaStore
import com.jeejio.img.bean.ImgAndVideoBean

/**
 * Author: JFangZ
 * Email:janezhang1901@163.com
 * Date: 2021/04/30 16:50
 * Description:
 */
class ImgAndVideoStrategy : IMediaStrategy<ImgAndVideoBean> {

    override fun getUri(): Uri {
        return MediaStore.Files.getContentUri("external")
    }

    override fun getSelection(): String {
        return "(" +
                MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE +
                " OR " +
                MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO +
                ")" +
                " AND " +
                // File size must greater than 0.
                MediaStore.Files.FileColumns.SIZE + ">0" +
                " AND " +
                // Duration must greater than 0 if it's video.
                "(" +
                MediaStore.Files.FileColumns.MEDIA_TYPE + "!=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO +
                " OR " +
                "(" +
                MediaStore.Files.FileColumns.MEDIA_TYPE + "=" + MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO + " AND duration>0" +
                ")" +
                ")"
    }

    override fun getSelectionArgs(): Array<String>? {
        return null
    }

    override fun getOrder(): String? {
        return null
    }

    override fun initBeanClass(): Class<ImgAndVideoBean> {
        return ImgAndVideoBean::class.java
    }
}
